import os
from typing import Any

class Config:
    def __init__(self):
        # 关闭flak的CSRF校验
        self.WTF_CSRF_ENABLED = _get_bool_env("WTF_CSRF_ENABLED")

        # 数据库配置
        self.SQLALCHEMY_DATABASE_URI = _get_env("SQLALCHEMY_DATABASE_URI")
        self.SQLALCHEMY_ENGINE_OPTIONS = {
            "pool_size":int(_get_env("SQLALCHEMY_POOL_SIZE")) ,
            "pool_recycle":int(_get_env("SQLALCHEMY_POOL_RECYCLE")) ,
        }
        self.SQLALCHEMY_ECHO = _get_bool_env("SQLALCHEMY_ECHO")



def _get_bool_env(key: str) -> bool:
    """从环境变量中获取布尔值型的配置项，如果找不到则返回默认值"""
    value: str = os.getenv(key)
    return value.lower() == "true" if value is not None else False

def _get_env(key: str) -> Any:
    return os.getenv(key)
    
